package website.haicheng.core.base;

import java.util.HashMap;

/**
 * @description:
 * @author: 582895699@qq.com
 * @time: 2021/2/9 下午 09:15
 */
public class Resp extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    private static final String CODE = "code";
    private static final String MESSAGE = "message";
    private static final String RESULT = "data";

    public Resp() {
        put(CODE, 200);
        put(MESSAGE, "success");
    }

    public static Resp ok() {
        return new Resp();
    }

    public static Resp ok(String message) {
        Resp resp = new Resp();
        resp.put(MESSAGE, message);
        return resp;
    }

    public static Resp ok(Object result) {
        Resp resp = new Resp();
        resp.put(RESULT, result);
        return resp;
    }

    public static Resp ok(String key, Object value) {
        Resp resp = new Resp();
        resp.put(key, value);
        return resp;
    }

    public static Resp error(int code, String message) {
        Resp resp = new Resp();
        resp.put(CODE, code);
        resp.put(MESSAGE, message);
        return resp;
    }

    public static Resp error(String message) {
        return error(500, message);
    }

    public static Resp error() {
        return error(500, "fail");
    }

    @Override
    public Object put(String key, Object value) {
        return super.put(key, value);
    }
}
